package edu.nwpu.zya.coreops.modules.dashboard.controller;

import edu.nwpu.zya.coreops.common.utils.R;
import edu.nwpu.zya.coreops.common.utils.ShiroUtils;
import edu.nwpu.zya.coreops.modules.alert.entity.HistoryEntity;
import edu.nwpu.zya.coreops.modules.alert.service.HistoryService;
import edu.nwpu.zya.coreops.modules.alert.service.StatisticService;
import edu.nwpu.zya.coreops.modules.dashboard.entity.AlertCountEntity;
import edu.nwpu.zya.coreops.modules.dashboard.entity.AlertTrendEntity;
import edu.nwpu.zya.coreops.modules.dashboard.service.DashboardService;
import edu.nwpu.zya.coreops.modules.dashboard.entity.InstanceCountEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("dashboard")
public class DashboardController {
    @Autowired
    private DashboardService dashboardService;

    @Autowired
    private HistoryService historyService;

    @Autowired
    private StatisticService statisticService;

    @RequestMapping("instance")
    public R instance(@RequestParam("type")Integer type){
        Long userId = ShiroUtils.getUserId();
        InstanceCountEntity instanceCountEntity =dashboardService.getInstanceCountByType(userId,type);
        return R.ok().put("instanceCount", instanceCountEntity);
    }

    @RequestMapping("alert/count")
    public R alertCount(){
        Long userId = ShiroUtils.getUserId();
        AlertCountEntity alertCountEntity=dashboardService.getAlertCount(userId);
        return R.ok().put("alertCount",alertCountEntity);
    }

    @RequestMapping("alert/history")
    public R alertHistory(){
        Long userId = ShiroUtils.getUserId();
        List<HistoryEntity> historyEntities=historyService.getHistoryByUserId(userId);
        return R.ok().put("alertHistory",historyEntities);
    }
    @RequestMapping("alert/trend")
    public R alertTrend(){
        Long userId = ShiroUtils.getUserId();
        List<AlertTrendEntity> alertTrendEntities=statisticService.getTodayAlertTrend(userId);

        return R.ok().put("alertTrend",alertTrendEntities);
    }

}
